package com.fdb.efp.console.api.rest;

import com.fdb.basic.framework.core.constant.DataRuleType;
import com.fdb.basic.framework.core.constant.ResponseData;
import com.fdb.basic.framework.web.controller.AbstractController;
import com.fdb.efp.console.service.facade.SRoleDataRuleService;
import com.fdb.efp.console.service.facade.BizPluginParamService;
import com.fdb.efp.console.service.vo.BizPluginParamVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class BizPluginParamController extends AbstractController  {
	
	@Autowired
	@Qualifier("bizPluginParamService")
	private BizPluginParamService bizPluginParamService;
	@Autowired
	@Qualifier("sRoleDataRuleService")
	private SRoleDataRuleService sRoleDataRuleService;

	
	/**
	 * 列表数据查询
	 * @param page
	 * @param size
	 * @return
	 */
	@RequestMapping(value="/biz/plugin/params", method=RequestMethod.POST)
	public @ResponseBody ResponseData<List<BizPluginParamVO>> queryBizPluginParamAll(
			@RequestBody BizPluginParamVO vo) {		
//		List<BizPluginParamVO> outputVo = this.executeQueryList("queryAll", bizPluginParamService, new Object[]{vo});
//		return getResponseData(outputVo);
		// 根据用户角色获取用户权限方案
		List<BizPluginParamVO> outputVo = null;
		//Map<String,String> dataRuleTypeMap = sRoleDataRuleService.getDataRuleType(httpRequest.getRequestURI(), getUserRoles());
		//DataRuleType dataRuleType = DataRuleType.getDataRuleType(dataRuleTypeMap == null ? null:dataRuleTypeMap.get(PubConstant.PERMIS_TYPE));
		DataRuleType dataRuleType =DataRuleType.getDataRuleType("01");
		//setUserInfoToVO(vo);
		// 根据权限方案调用不同的方案进行数据查询
		switch (dataRuleType) {
		case Owner:
			outputVo = bizPluginParamService.queryAllOwner(vo);
			break;
		case CurrOrg:
			outputVo = bizPluginParamService.queryAllCurrOrg(vo);
			break;
		case CurrDownOrg:
			outputVo = bizPluginParamService.queryAllCurrDownOrg(vo);
			break;
		default:
			outputVo = bizPluginParamService.queryAllOwner(vo);
			break;
		}
		return getResponseData(outputVo);
		
	}
	
	/**
	 * 根据组件ID查询参数
	 * @param vo
	 * @return
	 */
	@RequestMapping(value="/biz/plugin/paramsByPlugin", method=RequestMethod.GET)
	public @ResponseBody ResponseData<List<BizPluginParamVO>> queryBizPluginParamByPlugin(@RequestParam("bizPluginId") String bizPluginId) {		
		List<BizPluginParamVO> outputVo = bizPluginParamService.queryByPluginId(bizPluginId);
		return getResponseData(outputVo);
	}
	
	/**
	 * 根据主键查询详情
	 * @return
	 */
	@RequestMapping(value="/biz/plugin/param/{bizParamCode}{bizPluginId}/{bizParamIo}/", method=RequestMethod.GET)
	public @ResponseBody ResponseData<BizPluginParamVO> queryByPk(@PathVariable("bizParamCode") String bizParamCode,@PathVariable("bizPluginId") String bizPluginId,@PathVariable("bizParamIo") String bizParamIo) {		
		BizPluginParamVO inVo = new BizPluginParamVO();
				inVo.setBizParamCode(bizParamCode);
				inVo.setBizPluginId(bizPluginId);
				inVo.setBizParamIo(bizParamIo);
		BizPluginParamVO outputVo = bizPluginParamService.queryByPk(inVo);
		return getResponseData(outputVo);
		
	}
	
	/**
	 * 根据主键删除信息
	 * @param bizPluginParam
	 * @return
	 */
	@RequestMapping(value="/biz/plugin/param", method=RequestMethod.DELETE)
	public @ResponseBody ResponseData<Integer> deleteByPk(@RequestBody BizPluginParamVO inBizPluginParamVo) {		
		int outputVo = bizPluginParamService.deleteByPk(inBizPluginParamVo);
		return getResponseData(outputVo);
		
	}
	
	/**
	 * 根据主键更新信息
	 * @param inBizPluginParamVo
	 * @return
	 */
	@RequestMapping(value="/biz/plugin/param", method=RequestMethod.PUT)
	public @ResponseBody ResponseData<Integer> updateByPk(@RequestBody BizPluginParamVO inBizPluginParamVo) {		
		int outputVo = bizPluginParamService.updateByPk(inBizPluginParamVo);
		return getResponseData(outputVo);
		
	}
	
	/**
	 * 新增数据
	 * @param inBizPluginParamVo
	 * @return
	 */
	@RequestMapping(value="/biz/plugin/param", method=RequestMethod.POST)
	public @ResponseBody ResponseData<Integer> insertBizPluginParam(@RequestBody BizPluginParamVO inBizPluginParamVo) {
		int outputVo = bizPluginParamService.insertBizPluginParam(inBizPluginParamVo);
		return getResponseData(outputVo);
		
	}
}
